<?php

namespace app\api\controller\Pay;

use app\api\controller\Common;
use app\api\Logic\Pay\PayLogic;
use app\api\model\PayLogModel;

/**
 * 在线课程接口
 */
class Pay extends Common
{
    protected $noNeedLogin = ['*'];

    protected $payLogic;

    public function _initialize()
    {
        parent::_initialize();
        $this->payLogic = new PayLogic();
    }

    //下单插入订单总表
    public function pay(){
        $data = $this->request->param();

        $orderId = $this->payLogic->createOrder($data);
        if($orderId){
            $this->success('插入成功',['order_id' => $orderId]);
        }
        $this->error('插入失败');
    }

    //订单支付回调
    public function pay_result($order_sn){
        $pay_log = PayLogModel::where('order_sn',$order_sn)->find();
        if(empty($pay_log)){
            $this->error('订单不存在');
        }
        //判断订单类型 各自支付回调
        switch ($pay_log['controller']){
            case '订单类型':
                action('api/' . $pay_log['controller'] . '/pay_result', [$pay_log['id']]);
                break;
            default:
                break;
        }
    }


}
